home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
games2
/
rotise12.zip
/
TRANSACT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-03
|
16KB
|
565 lines
/* transact.c
Jonathan Arnold 1991
All the functions to do transactions during the season. Ones like:
move - change slots for a player
release - remove player from roster and send to free agent pool
claim - claim player in free agent pool
reserve - add player to rotisserie team's reserve
activate - activate a player off the reserve
trade - trade player from one rotisserie team to another
expand - do September roster expansion
*/
#include <stdio.h>
#include <string.h>
#ifdef __TURBOC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include "rotise.h"
/* External data referenced */
extern CMDLIST CmdTable[]; /* cmdtable.c */
extern int Cmd; /* rotise.c */
extern int InputLine; /* Line # of current file */
extern BOOL Verbose; /* How talkative to be */
extern char *InputFilename; /* Filename being read */
extern RDB_TEAM *RotoTeams; /* roster.c - First team in list */
extern int Weeks; /* stenog.c - How many intervals read in */
extern char IntvDate[MAX_DATE+1]; /* Date string for current interval */
extern int SalFree; /* Free agent salary */
extern int CostRelease;
extern int CostClaim;
extern int CostReserve;
extern int CostExpand;
extern int CostWClaim;
extern int CostActive;
/* External routines used */
/* NONE */
/* Local data publicly available */
/* NONE */
/* Local routine prototypes */
BOOL move PROTO( (int token, char *tokens[]) );
BOOL release PROTO( (int token, char *tokens[]) );
BOOL claim PROTO( (int token, char *tokens[]) );
BOOL reserve PROTO( (int token, char *tokens[]) );
BOOL activate PROTO( (int token, char *tokens[]) );
BOOL trade PROTO( (int token, char *tokens[]) );
BOOL expand PROTO( (int token, char *tokens[]) );
/* Private data */
/* NONE */
/*
BOOL move( int tokcnt, char *tokens[] )
Move a player from one slot to another.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_MV_RTEAM 1 /* Rotisserie team */
#define ARG_MV_PK1 2 /* Player key, last name */
#define ARG_MV_PK2 3 /* Player key, first initial */
#define ARG_MV_SLOT 4 /* New slot */
BOOL move ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
int slotN;
RDB_TEAM *rteam;
RDB_PLAYER *player;
if ( tokcnt < ARG_MV_SLOT )
ARGCNT_ERR();
VERBOSE( 4, "\Move %s to slot ", tokens[ARG_MV_PK1] );
VERBOSE( 4, "%s.\n", tokens[ARG_MV_SLOT] );
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[ARG_MV_RTEAM] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Move - Roto team Not Found: ", tokens[ARG_MV_RTEAM] );
return TRUE;
}
for ( player = rteam->players; player != NULL; player = player->next )
{ /* now, see if we can find player on active roster */
if ( player->status == STATUS_ACTIVE )
{ /* found active player, is this the one */
if ( stricmp( player->pname.pn_lname, tokens[ARG_MV_PK1] ) == 0 &&
stricmp( player->pname.pn_fname, tokens[ARG_MV_PK2] ) == 0 )
{ /* found the player */
break;
}
}
}
if ( player == NULL )
{ /* unable to find player on active roster */
rdb_error( "Move - Player not on active roster: ", tokens[ARG_MV_PK1] );
return TRUE;
}
/* change the slot */
slotN = slot_find( tokens[ARG_MV_SLOT] );
if ( slotN < 0 )
{ /* bad slot */
rdb_error( "Move - Invalid slot: ", tokens[ARG_MV_SLOT] );
return TRUE;
}
player->slot = slotN;
return TRUE;
}
/*
BOOL release( int tokcnt, char *tokens[] )
Release a player from a rotisserie team and add him to the free agent
pool
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_REL_TEAM 1 /* Team doing release */
#define ARG_REL_PK1 2 /* Player key, last name */
#define ARG_REL_PK2 3 /* Player key, first initial */
#define ARG_REL_WAIVE 4 /* Being waived? */
BOOL release ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
RDB_TEAM *rteam;
RDB_PLAYER *player;
PDATA *pdata;
if ( tokcnt < ARG_REL_WAIVE )
ARGCNT_ERR();
VERBOSE( 4, "\tRelease from %s: ", tokens[ARG_REL_TEAM] );
VERBOSE( 4, "%s.\n", tokens[ARG_REL_PK1] );
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[ARG_REL_TEAM] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Release - Team Not Found: ", tokens[ARG_REL_TEAM] );
return TRUE;
}
for ( player = rteam->players; player != NULL; player = player->next )
{ /* now, see if we can find player on active roster */
if ( player->status != STATUS_OLD )
{ /* found active player, is this the one */
if ( stricmp( player->pname.pn_lname, tokens[ARG_REL_PK1] ) == 0 &&
stricmp( player->pname.pn_fname, tokens[ARG_REL_PK2] ) == 0 )
{ /* found the player */
break;
}
}
}
if ( player == NULL )
{ /* unable to find player on active roster */
rdb_error( "Release - Player not on active roster: ", tokens[ARG_REL_PK1] );
return TRUE;
}
if ( player->status != STATUS_RESERVE )
player->end = Weeks;
player->status = STATUS_OLD;
pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
TRUE );
if ( pdata == NULL )
{ /* try to find as pitcher */
pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
FALSE );
}
pdata->zorch = PLAYER_FREE;
if ( tokcnt == (ARG_REL_WAIVE+1) )
{ /* waived parameter passed, so add to waiver wire */
pdb_status( &player->pname, WAIVED_STRING, IntvDate, PLAYER_FREE, Weeks );
}
else
{ /* otherwise, just release */
pdb_status( &player->pname, "", IntvDate, PLAYER_FREE, Weeks );
}
rteam->money_spent += CostRelease;
return TRUE;
}
/*
BOOL claim( int tokcnt, char *tokens[] )
Claim a player from the free agent pool.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_CLM_TEAM 1 /* Rotisserie Team Key */
#define ARG_CLM_PK1 2 /* Player Key 1 - last name */
#define ARG_CLM_PK2 3 /* Player Key 2 - first initial(s) */
#define ARG_CLM_SLOT 4 /* Slot */
#define ARG_CLM_NAME 5 /* First word of full name */
BOOL claim ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
RDB_TEAM *rteam;
RDB_PLAYER *player, *wplayer;
PDATA *pdata;
char salary[20];
char contract[5];
int kk;
int slotN;
char batter;
if ( tokcnt < ARG_CLM_NAME )
ARGCNT_ERR();
VERBOSE( 4, "\tClaim for %s,", tokens[ARG_CLM_TEAM] );
VERBOSE( 4, " %s.\n", tokens[ARG_CLM_PK1] );
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[ARG_CLM_TEAM] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Claim - Team Not Found: ", tokens[ARG_CLM_TEAM] );
return TRUE;
}
pdata = pdb_pdata( tokens[ARG_CLM_PK1], tokens[ARG_CLM_PK2],
batter = TRUE );
if ( pdata == NULL )
{ /* try to find as pitcher */
pdata = pdb_pdata( tokens[ARG_CLM_PK1], tokens[ARG_CLM_PK2],
batter = FALSE );
}
if ( pdata == NULL || pdata->zorch != PLAYER_FREE )
{ /* not a free agent; bummer man */
rdb_error( "Claim - Player not free agent: ", tokens[ARG_CLM_PK1] );
}
slotN = slot_find( tokens[ARG_CLM_SLOT] );
if ( slotN < 0 )
{ /* bad slot */
rdb_error( "Claim - Invalid slot: ", tokens[ARG_CLM_SLOT] );
return TRUE;
}
player = (RDB_PLAYER *)calloc( 1, sizeof( RDB_PLAYER ) );
if ( player == NULL )
{ /* couldn't get memory, so quit */
rdb_error( "Claim - Unable to get memory!", NULL );
return FALSE;
}
/* now muck with the tokens to use build_player to set up player data */
for ( kk = ARG_CLM_NAME; kk < tokcnt; kk++ )
{ /* move full name to where build_player wants it */
tokens[ARG_ADD_NAME+(kk-ARG_CLM_NAME)] = tokens[kk];
}
/* get free agent salary */
sprintf( salary, "%d", SalFree );
tokens[ARG_ADD_SAL] = salary;
/* free agent has first year contract */
contract[0] = 'A';
contract[1] = '\0';
tokens[ARG_ADD_CONT] = contract;
build_player( player, ARG_ADD_NAME+(kk-ARG_CLM_NAME), tokens );
player->pname.batter = batter;
if ( rteam->players == NULL )
{ /* first player - probably shouldn't happen with claim! */
rteam->players = player;
}
else
{ /* find last one */
for ( wplayer = rteam->players; wplayer->next != NULL; wplayer = wplayer->next )
{ /* skip through the list to find last one */
}
wplayer->next = player;
}
player->start = Weeks + 1;
player->end = Weeks + 1;
/* add to cost based on whether this is a waiver claim */
if ( pdata != NULL && strcmp( pdata->status, WAIVED_STRING ) == 0 )
{ /* on waivers */
rteam->money_spent += CostWClaim;
}
else
{ /* free agent claim */
rteam->money_spent += CostClaim;
}
/* set data to show no longer a free agent */
pdb_status( &player->pname, "", IntvDate, PLAYER_CLAIMED, Weeks+1 );
return TRUE;
}
/*
BOOL reserve( int tokcnt, char *tokens[] )
Reserve a player. Move player from the active roster onto a team's reserve
list.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_RES_TEAM 1 /* Rotisserie team keyword */
#define ARG_RES_PK1 2 /* Player key 1 - last name */
#define ARG_RES_PK2 3 /* Player key 2 - first name */
BOOL reserve ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
RDB_TEAM *rteam;
RDB_PLAYER *player;
if ( tokcnt < (ARG_RES_PK2+1) )
ARGCNT_ERR();
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[ARG_RES_TEAM] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Reserve - Team Not Found: ", tokens[ARG_RES_TEAM] );
return TRUE;
}
for ( player = rteam->players; player != NULL; player = player->next )
{ /* now, see if we can find player on active roster */
if ( player->status == STATUS_ACTIVE )
{ /* found active player, is this the one */
if ( stricmp( player->pname.pn_lname, tokens[ARG_RES_PK1] ) == 0 &&
stricmp( player->pname.pn_fname, tokens[ARG_RES_PK2] ) == 0 )
{ /* found the player */
break;
}
}
}
if ( player == NULL )
{ /* unable to find player on active roster */
rdb_error( "Reserve - Player not on active roster: ", tokens[ARG_RES_PK1] );
return TRUE;
}
/* player->end = (Weeks>=player->start?Weeks:player->start); */
player->end = Weeks;
player->status = STATUS_RESERVE;
rteam->money_spent += CostReserve;
return TRUE;
}
/*
BOOL activate( int tokcnt, char *tokens[] )
Move a player from the reserve list onto the active roster.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_ACT_TEAM 1 /* Rotisserie team keyword */
#define ARG_ACT_PK1 2 /* Player key 1 - last name */
#define ARG_ACT_PK2 3 /* Player key 2 - first name */
#define ARG_ACT_SLOT 4 /* Optional new slot */
BOOL activate ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
RDB_TEAM *rteam;
RDB_PLAYER *player, *wplayer;
RDB_SLOT *slotP;
PDATA *pdata;
char salary[10];
if ( tokcnt < (ARG_ACT_PK2+1) )
ARGCNT_ERR();
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[ARG_ACT_TEAM] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Activate - Team Not Found: ", tokens[ARG_ACT_TEAM] );
return TRUE;
}
for ( player = rteam->players; player != NULL; player = player->next )
{ /* now, see if we can find player on reserved roster */
if ( player->status == STATUS_RESERVE )
{ /* found reserved player, is this the one */
if ( stricmp( player->pname.pn_lname, tokens[ARG_ACT_PK1] ) == 0 &&
stricmp( player->pname.pn_fname, tokens[ARG_ACT_PK2] ) == 0 )
{ /* found the player */
break;
}
}
}
if ( player == NULL )
{ /* unable to find player on reserved roster */
rdb_error( "Activate - Player not on reserved roster: ", tokens[ARG_ACT_PK1] );
return TRUE;
}
/* make player be old now and create a new one */
player->status = STATUS_OLD;
/* now muck with the tokens to use build_player to set up player data */
if ( tokcnt <= ARG_ACT_SLOT )
{ /* no slot, use old player one */
slotP = slot_get( player->slot );
tokens[ARG_ADD_SLOT] = ( slotP == NULL ) ? "??" : slotP->slot;
}
else
{ /* use passed one */
tokens[ARG_ADD_SLOT] = tokens[ARG_ACT_SLOT];
}
tokens[ARG_ADD_NAME] = player->name;
/* get old salary */
sprintf( salary, "%d", player->salary );
tokens[ARG_ADD_SAL] = salary;
/* get old contract */
tokens[ARG_ADD_CONT] = contract_string( player->contract );
player = (RDB_PLAYER *)calloc( 1, sizeof( RDB_PLAYER ) );
if ( player == NULL )
{ /* couldn't get memory, so quit */
rdb_error( "Activate - Unable to get memory!", NULL );
return FALSE;
}
build_player( player, ARG_ADD_NAME+1, tokens );
/* find last one */
for ( wplayer = rteam->players; wplayer->next != NULL; wplayer = wplayer->next )
{ /* skip through the list to find last one */
}
wplayer->next = player;
player->start = Weeks + 1;
player->end = Weeks + 1;
/* add to cost for activating */
rteam->money_spent += CostActive;
/* now, clear status if he had one */
pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
TRUE );
if ( pdata == NULL )
{ /* try to find as pitcher */
pdata = pdb_pdata( tokens[ARG_REL_PK1], tokens[ARG_REL_PK2],
FALSE );
}
memset( pdata->status, 0, 5 );
memset( pdata->date, 0, MAX_DATE );
return TRUE;
}
/*
BOOL trade( int tokcnt, char *tokens[] )
Trade player from one rotisserie team to another.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL trade ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}
/*
BOOL expand( int tokcnt, char *tokens[] )
Add a player to the roster. No slot is associated with this player. Usually
used for September roster expansion, which is now unlimited.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL expand ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}